﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing;

namespace Licenta1.Shapes
{
[Serializable]
    class Point : Shape
    {

        Expression parameters;
        double x, y;
        bool init = false;

        public Point(Context con, Expression param)
            : base(con)
        {
            parameters = param;
        }

        public Point(Context con, double xx, double yy)
            : base(con)
        {
            x = xx;
            y = yy;
            parameters = null;
            init = true;
        }

        private void CheckParameters()
        {
            object o1 = null, o2 = null;

            try
            {
                ParameterList p_list = (ParameterList)parameters;

                o1 = (double)p_list.FirstValue;
                o2 = (double)p_list.SecondValue;

                if (o1 != null)
                    x = (double)o1;

                if (o2 != null)
                    y = (double)o2;
            }
            catch (Exception)
            {
                Console.WriteLine(parameters.Value.ToString());
                x = 0; y = 0;
            }
            //init = false;
        }

        public double X
        {
            get
            {
                if (!init)
                    CheckParameters();
                return x;
            }
            set { x = value; }
        }

        public double Y
        {
            get
            {
                if (!init)
                    CheckParameters();
                return y;
            }
            set { y = value; }
        }

        public override string Display()
        {
            if (!init)
                CheckParameters();
            return "[x = " + x + ", y = " + y + "]";
        }

        public override object Value
        {

            get
            {
                if (!init)
                    CheckParameters();
                return this;
            }
        }

        public override object GetClone()
        {
            return new Point(context, x, y);
        }
    }
}
